/**
 * 
 */
package com.ruyipu.forum.model;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;

import com.ruyipu.forum.base.Constants;
import com.ruyipu.forum.interfaces.IUserModel;

/**
 * @author donald
 * 
 */
public final class UserModel implements IUserModel {
	private static final String USER_LOGIN_URL = Constants.API_URL
			+ "entry/signin";
	private static final String USER_REGISTER_URL = Constants.API_URL
			+ "entry/register";
	@SuppressWarnings("unused")
	private static final String USER_PROFILE_URL = Constants.API_URL
			+ "user/profile/%s";

	private static UserModel userModel;

	private UserModel() {
	}

	public static UserModel getInstance() {
		if (null == userModel) {
			userModel = new UserModel();
		}
		return userModel;
	}

	public JSONObject login(Context context, String userName, String password)
			throws UnsupportedEncodingException, ClientProtocolException,
			IOException, JSONException {
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("Form/Email", userName));
		params.add(new BasicNameValuePair("Form/Password", password));
		return Model.post(context, USER_LOGIN_URL, params);
	}

	public JSONObject register(Context context, String userName, String email,
			String password, String gender)
			throws UnsupportedEncodingException, ClientProtocolException,
			IOException, JSONException {
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("User/Email", email));
		params.add(new BasicNameValuePair("User/Name", userName));
		params.add(new BasicNameValuePair("User/Password", password));
		// params.add(new BasicNameValuePair("User/PasswordMatch", _password));
		params.add(new BasicNameValuePair("User/Gender", gender));
		params.add(new BasicNameValuePair("User/TermsOfService", "1"));
		return Model.post(context, USER_REGISTER_URL, params);
	}

	public JSONObject getUserProfile(Context context, int userId) {
		// TODO Auto-generated method stub
		return null;
	}
}
